package com.ruoyi.business.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.WxNews;
import com.ruoyi.business.service.IWxNewsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 社区资讯Controller
 * 
 * @author asher
 * @date 2021-11-13
 */
@RestController
@RequestMapping("/business/news")
public class WxNewsController extends BaseController
{
    @Autowired
    private IWxNewsService wxNewsService;

    /**
     * 查询社区资讯列表
     */
    @GetMapping("/list")
    public TableDataInfo list(WxNews wxNews)
    {
        startPage();
        List<WxNews> list = wxNewsService.selectWxNewsList(wxNews);
        return getDataTable(list);
    }

    /**
     * 导出社区资讯列表
     */
    @PreAuthorize("@ss.hasPermi('business:news:export')")
    @Log(title = "社区资讯", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(WxNews wxNews)
    {
        List<WxNews> list = wxNewsService.selectWxNewsList(wxNews);
        ExcelUtil<WxNews> util = new ExcelUtil<WxNews>(WxNews.class);
        return util.exportExcel(list, "社区资讯数据");
    }

    /**
     * 获取社区资讯详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:news:query')")
    @GetMapping(value = "/{newsId}")
    public AjaxResult getInfo(@PathVariable("newsId") Integer newsId)
    {
        return AjaxResult.success(wxNewsService.selectWxNewsByNewsId(newsId));
    }

    /**
     * 新增社区资讯
     */
    @PreAuthorize("@ss.hasPermi('business:news:add')")
    @Log(title = "社区资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxNews wxNews)
    {
        return toAjax(wxNewsService.insertWxNews(wxNews));
    }

    /**
     * 修改社区资讯
     */
    @PreAuthorize("@ss.hasPermi('business:news:edit')")
    @Log(title = "社区资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxNews wxNews)
    {
        return toAjax(wxNewsService.updateWxNews(wxNews));
    }

    /**
     * 删除社区资讯
     */
    @PreAuthorize("@ss.hasPermi('business:news:remove')")
    @Log(title = "社区资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{newsIds}")
    public AjaxResult remove(@PathVariable Integer[] newsIds)
    {
        return toAjax(wxNewsService.deleteWxNewsByNewsIds(newsIds));
    }
}
